package com.wangrui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangrui.mapper.RoleMapper;
import com.wangrui.pojo.Role;
import com.wangrui.pojo.School;
import com.wangrui.mapper.SchoolMapper;
import com.wangrui.pojo.Semester;
import com.wangrui.service.SchoolService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王锐
 * @since 2020-07-05
 */
@Service
public class SchoolServiceImpl extends ServiceImpl<SchoolMapper, School> implements SchoolService {

    @Autowired
    private SchoolMapper schoolMapper;
    @Override
    public School getSchoolName(Integer sid) {
        QueryWrapper<School> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",sid);
        return schoolMapper.selectOne(queryWrapper);
    }

    @Override
    public List<School> queryAllSchool() {
        return schoolMapper.selectList(null);
    }

    @Override
    public Map<String, Object> Allschools(int start, int end) {
        Page<School> page = new Page<>(start,end);
        schoolMapper.selectPage(page,null);

        Map<String, Object> map = new HashMap<>();
        map.put("rows", page.getRecords());
        map.put("total", schoolMapper.selectCount(null));
        return map;
    }

    @Override
    public int getTotal() {
        return schoolMapper.selectCount(null);
    }

    @Override
    public int schoolSave(School school) {
        return schoolMapper.insert(school);
    }

    @Override
    public int schoolUpdate(School school) {
        return schoolMapper.updateById(school);
    }

    @Override
    public int schoolDelete(int  id) {
        return schoolMapper.deleteById(id);
    }
}
